package com.itheima.recursiondemo;

public class Test {

    public static void main(String[] args) {

        //递归
        //递归算法的三要素：1、递归的公式；2、递归终结点；3、递归的方向必须走向终结点

        System.out.println(factorial(5));

        System.out.println(eatPeach(1));
        System.out.println(eatPeach(2));
        System.out.println(eatPeach(3));
    }

    //计算n的阶乘
    public static int factorial(int n) {
        if (n == 1) {
            return 1;
        }
        return n * factorial(n - 1);
    }

    //猴子吃桃问题
    public static int eatPeach(int day) {
        if (day == 10) {
            return 1;
        }
        return 2 * eatPeach(day + 1) + 2;
    }

}
